package com.xinzhi.service.impl;

import cn.hutool.core.util.StrUtil;
import com.xinzhi.mapper.ReasonforMapper;
import com.xinzhi.pojo.dto.Teshujiafen;
import com.xinzhi.service.ReasonforService;
import com.xinzhi.utils.RedisUtils;
import com.xinzhi.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReasonforServiceImol implements ReasonforService {
    /**
     * 特殊加分申诉申请的查询
     */
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private ReasonforMapper reasonforMapper;
    @Override
    public Result selectappraisal() {
        String teshu = (String) redisUtils.get("teshu");
        if (StrUtil.isNotEmpty(teshu)){
            return Result.ok(teshu);
        }

        List<Teshujiafen> reasonforapplication = reasonforMapper.getReasonforapplication();
        if (reasonforapplication!=null){
            redisUtils.set("teshu",reasonforapplication);
            return Result.ok(reasonforapplication);
        }else {
            return Result.error("查询失败");

        }
    }


    /**
     * 逻辑删除
     * @param Causeofappeal
     * @param deleted
     * @return
     */

    @Override
    public Result updateReasonfor(String Causeofappeal, Integer deleted) {
        if (Causeofappeal == null || deleted == null){
            return Result.error("输入的东西为空");
        } else if (deleted != 1) {
            return Result.error("输入的删除状态不对");
        }else {
            int i = reasonforMapper.updateReasonfor(Causeofappeal, deleted);
            return i > 0 ? Result.ok("修改成功") : Result.error("修改失败");
        }
    }
}
